package com.product.android.business.broadcast;

import java.util.ArrayList;

import com.product.android.business.ApplicationVariable;
import com.product.android.business.login.BindUser;
import com.product.android.commonInterface.album.Image;
import com.product.android.commonInterface.contact.BlackListPerson;
import com.product.android.commonInterface.contact.OapUser;
import com.product.android.commonInterface.contact.TagInfo;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.LocalBroadcastManager;

/**
 * 从个人主页进入相册、标签等页面返回时通知刷新
 * 本来是用startactivityforresult就可以了，但是校友这边我的主页是singltask模式，onactivityresult无法运行，所以统一改用广播
 * PARAM_MODIFY_AVARTAR、PARAM_PERSONALITYTAG、PARAM_ALBUM、PARAM_BLACKLIST、PARAM_MODIFY_MY_INFO
 * 上面这些广播已经控制了只有当前用户才会发，其余广播都会发，在自己和他人公用的界面收到广播需要判断用户是否符合要求
 * ClassName:PersonInfoBroadHelper
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 * 
 * @author   黄永鑫		
 * @version  
 * @since    Ver 1.1
 * @Date	 2014	2014-4-4		上午11:27:43
 *
 * @see
 */
public enum PersonInfoBroadHelper {
	INSTANCE;
    
    //个人主页中间滑动条更新广播
    public static String ACTION_HOMEPAGE_UPDATE = "com.nd.android.u.cloud.homepageupdate";
    
    public static class ParamKey{
    	public static final String PARAM_KEY_HEADURI = "headUri";
    	public static final String PARAM_KEY_SHOWURI = "showUriStr";
        public static final String PARAM_KEY_CODE = "code";
        public static final String PARAM_KEY_OAPUID = "oapuid";
        public static final String PARAM_KEY_UAPUID = "uapuid";
        public static final String PARAM_KEY_OAPUSER = "oapuser";
        public static final String PARAM_KEY_BINDUSER = "binduser";
        public static final String PARAM_KEY_ALBUMLIST = "albumlist";
        public static final String PARAM_KEY_TAGLIST = "taglist";
        public static final String PARAM_KEY_BLACKLIST = "blacklist";
    }
    
    public static class ParamCode {
    	public final static int PARAM_MODIFY_AVARTAR 	= 1000; // 从ModifyPortraitActivity界面选择头像后的通知，针对当前登录用户
    	                                                        // 头像还没传成功，带参数给接收界面去上传
    	public final static int PARAM_PERSONALITYTAG 	= 1001; // 跳转到标签界面
    	public final static int PARAM_ALBUM 			= 1002; // 跳转到相册界面
    	public final static int PARAM_BLACKLIST 		= 1003; // 跳转到黑名单界面
    	public final static int PARAM_MODIFY_MY_INFO 	= 1004; // 我的个人信息有修改通知
    	public final static int PARAM_MODIFY_OTHER_INFO = 1005; // 他人信息有修改通知
    	public final static int PARAM_UPDATE_AVARTAR    = 1006; // 更新头像成功后通知刷新界面
    }
    
    /**
     * 对oapuid判断是否需要发送广播
     * @n<b>函数名称</b>     :isNeedSendBroadByOapuid
     * @brief
     * @see
     * @since    Ver 1.1
     * @param  @param oapuid
     * @param  @return
     * @return boolean
     * @<b>作者</b>          :  黄永鑫
     * @<b>创建时间</b>      :  2014-4-4下午1:40:49
     */
    public boolean isNeedSendBroadByOapuid(long oapuid){
    	if(oapuid == ApplicationVariable.INSTANCE.getIUser().getOapUid())
    		return true;
    	return false;
    }
    
    /**
     * 对uapuid判断是否需要发送广播
     * @n<b>函数名称</b>     :isNeedSendBroadByUapuid
     * @brief
     * @see
     * @since    Ver 1.1
     * @param  @param uapuid
     * @param  @return
     * @return boolean
     * @<b>作者</b>          :  黄永鑫
     * @<b>创建时间</b>      :  2014-4-4下午1:41:30
     */
    public boolean isNeedSendBroadByUapuid(long uapuid){
    	if(uapuid == ApplicationVariable.INSTANCE.getIUser().getUapUid())
    		return true;
    	return false;
    }
	
	/**
	 * 修改头像广播
	 * @n<b>函数名称</b>     :sendModifyAvaBroadCast
	 * @brief
	 * @see
	 * @since    Ver 1.1
	 * @param  @param mcontext
	 * @param  @param headUri
	 * @param  @param showUri
	 * @return void
	 * @<b>作者</b>          :  黄永鑫
	 * @<b>创建时间</b>      :  2014-4-4下午4:49:27
	 */
	public void sendModifyAvaBroadCast(Context mcontext, Uri headUri, Uri showUri){
		Intent message = new Intent(ACTION_HOMEPAGE_UPDATE);
		message.putExtra(ParamKey.PARAM_KEY_CODE, ParamCode.PARAM_MODIFY_AVARTAR);
		message.putExtra(ParamKey.PARAM_KEY_HEADURI, headUri);
		message.putExtra(ParamKey.PARAM_KEY_SHOWURI, showUri);
		LocalBroadcastManager.getInstance(mcontext).sendBroadcast(message);
	}
	
	/**
	 * 更新我的信息广播
	 * @param context
	 * @param oapUser
	 */
	public void sendModifyMyInfoBroadCast(Context mcontext, BindUser bindUser){
		Intent message = new Intent(ACTION_HOMEPAGE_UPDATE);
		message.putExtra(ParamKey.PARAM_KEY_CODE, ParamCode.PARAM_MODIFY_MY_INFO);
		message.putExtra(ParamKey.PARAM_KEY_BINDUSER, bindUser);
		LocalBroadcastManager.getInstance(mcontext).sendBroadcast(message);
	}
	
	/**
	 * 更新他人信息广播
	 * @param context
	 * @param oapUser
	 */
	public void sendModifyOtherInfoBroadCast(Context mcontext, long oapuid, OapUser oapUser){
		Intent message = new Intent(ACTION_HOMEPAGE_UPDATE);
		message.putExtra(ParamKey.PARAM_KEY_CODE, ParamCode.PARAM_MODIFY_OTHER_INFO);
		message.putExtra(ParamKey.PARAM_KEY_OAPUID, oapuid);
		message.putExtra(ParamKey.PARAM_KEY_OAPUSER, oapUser);
		LocalBroadcastManager.getInstance(mcontext).sendBroadcast(message);
	}
	
	/**
	 * 个人相册更新
	 * @param params
	 * @param imageList
	 */
	public void sendModifyAlbumBroadCast(Context mcontext, long uapuid, ArrayList<Image> imageList){
		if(!isNeedSendBroadByUapuid(uapuid))return;
		Intent message = new Intent(ACTION_HOMEPAGE_UPDATE);
		message.putExtra(ParamKey.PARAM_KEY_CODE, ParamCode.PARAM_ALBUM);
		message.putExtra(ParamKey.PARAM_KEY_UAPUID, uapuid);
		message.putExtra(ParamKey.PARAM_KEY_ALBUMLIST, imageList);
		LocalBroadcastManager.getInstance(mcontext).sendBroadcast(message);
	}
	
	/**
	 * 个人标签更新
	 * @param params
	 * @param imageList
	 */
	public void sendPersonalTagBroadCast(Context mcontext, long oapuid, ArrayList<TagInfo> tagList){
		if(!isNeedSendBroadByOapuid(oapuid))return;
		Intent message = new Intent(ACTION_HOMEPAGE_UPDATE);
		message.putExtra(ParamKey.PARAM_KEY_CODE, ParamCode.PARAM_PERSONALITYTAG);
		message.putExtra(ParamKey.PARAM_KEY_OAPUID, oapuid);
		message.putExtra(ParamKey.PARAM_KEY_TAGLIST, tagList);
		LocalBroadcastManager.getInstance(mcontext).sendBroadcast(message);
	}
	
	/**
	 * 黑名单更新
	 * @param uapuid
	 * @param isdel
	 */
	public void sendBlackListBroadCast(Context mcontext, ArrayList<BlackListPerson> blackList){
		Intent message = new Intent(ACTION_HOMEPAGE_UPDATE);
		message.putExtra(ParamKey.PARAM_KEY_CODE, ParamCode.PARAM_BLACKLIST);
		message.putExtra(ParamKey.PARAM_KEY_BLACKLIST, blackList);
		LocalBroadcastManager.getInstance(mcontext).sendBroadcast(message);
	}
	
	/**
	 * 更新头像成功后通知刷新界面
	 * @n<b>函数名称</b>     :sendUpdateAvaBroadCast
	 * @brief
	 * @see
	 * @since    Ver 1.1
	 * @param  @param mcontext
	 * @return void
	 * @<b>作者</b>          :  黄永鑫
	 * @<b>创建时间</b>      :  2014-4-9下午3:32:01
	 */
	public void sendUpdateAvaBroadCast(long oapuid) {
		Intent message = new Intent(ACTION_HOMEPAGE_UPDATE);
		message.putExtra(ParamKey.PARAM_KEY_CODE,
				ParamCode.PARAM_UPDATE_AVARTAR);
		message.putExtra(ParamKey.PARAM_KEY_OAPUID, oapuid);
		LocalBroadcastManager.getInstance(
				ApplicationVariable.INSTANCE.applicationContext).sendBroadcast(
				message);
	}

}
